import React, { Component } from 'react'
import {ListBox} from '../../../components'

import {fetchData} from '../../../components/AjaxConsumer'
import {  Button, Modal, Form, Input, Radio,Upload, Icon } from 'antd';
export default class ListProOutInSnPage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            tableColumn: {},
            searchComponentData: [],
            visible: false,
        };
        //行操作列表
        this.rowOperation = [
            {
                handleName: 'edit',
                iconClass: 'cellEdit'
            }, {
                handleName: 'delete',
                iconClass: 'cellDele'
            }, {
                handleName: 'assignUser',
                iconClass: 'cellRole'
            }
        ];
        //header 操作列表
        this.headerOperation = [
            //{
            //    handleName: 'delete',
            //    showName: '删除',
            //    iconClass: 'delete',
            //    permission: 'rawbarcode-del'
            //},{
            //    handleName: 'upload',
            //    showName: '打印',
            //    iconClass: 'upload',
            //    permission: 'rawbarcode-print'
            //}
        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        this.tableColumn = {
            storageKey: 'orderInSnOutInId',
            data: [
            {
                showName: '批次号',
                columnName: 'userDefined2',
                columnWidth: 120
            }, {
                showName: '条码',
                columnName: 'barcode',
                columnWidth: 130
            }, {
                showName: '型号',
                columnName: 'model',
                columnWidth: 120
            }, {
                showName: '品名',
                columnName: 'productName',
                columnWidth: 90
            }, {
                showName: '定量',
                columnName: 'density',
                columnWidth: 90
            }, {
                showName: '规格',
                columnName: 'spec',
                columnWidth: 90
            }, {
                showName: '生产机号',
                columnName: 'machineNumber',
                columnWidth: 110,
                showOption: []
            }, {
                showName: '等级',
                columnName: 'grade',
                columnWidth: 90,
                showOption:[
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'1',
                        optionShow:'一等品'
                    },{
                        optionKey:'2',
                        optionShow:'二等品'
                    },{
                        optionKey:'3',
                        optionShow:'处理品'
                    }
                ]
            }, {
                showName: '级别',
                columnName: 'level',
                columnWidth: 90,
                showOption:[
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'A',
                        optionShow:'A'
                    },{
                        optionKey:'B',
                        optionShow:'B'
                    },{
                        optionKey:'C',
                        optionShow:'C'
                    },{
                        optionKey:'D',
                        optionShow:'D'
                    }
                ]
            }, {
            //     showName: '类型',
            //     columnName: 'type',
            //     columnWidth: 90,
            //     showOption:[
            //     {
            //         optionKey:'',
            //             optionShow:''
            //         },{
            //             optionKey:'0',
            //             optionShow:'正品'
            //         },{
            //             optionKey:'1',
            //             optionShow:'样品'
            //         }
            //     ]
            // }, {
            //     showName: '打印状态',
            //     columnName: 'status',
            //     columnWidth: 110,
            //     showOption:[
            //         {
            //         optionKey:'',
            //             optionShow:''
            //         },{
            //             optionKey:'0',
            //             optionShow:'未打印'
            //         },{
            //             optionKey:'1',
            //             optionShow:'已打印'
            //         }
            //     ]
            // }, {
                showName: '入库状态',
                columnName: 'userDefined1',
                columnWidth: 110,
                showOption:[
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'0',
                        optionShow:'未入库'
                    },{
                        optionKey:'1',
                        optionShow:'已入库'
                    }
                ]
            }, {
                showName: '生产条码方式',
                columnName: 'userDefined8',
                columnHidden: true,
                foreverHidden: true,
                columnWidth: 130,
                showOption:[
                    {
                        optionKey: 'TH',
                        optionShow: '退货'
                    }
                ]
            }, {
                showName: '创建人',
                columnName: 'createBy',
                columnHidden: true,
            }
        ]
        };

        //搜索属性配置
        this.searchComponentData = [
            {
                showName: '等级',
                name: 'grade',
                type: 'select',
                optionList:[
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'1',
                        optionShow:'一等品'
                    },{
                        optionKey:'2',
                        optionShow:'二等品'
                    },{
                        optionKey:'3',
                        optionShow:'处理品'
                    }
                ]
            },{
                showName: '级别',
                name: 'level',
                type: 'select',
                optionList:[
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'A',
                        optionShow:'A'
                    },{
                        optionKey:'B',
                        optionShow:'B'
                    },{
                        optionKey:'C',
                        optionShow:'C'
                    },{
                        optionKey:'D',
                        optionShow:'D'
                    }
                ]
            },{
            //     showName: '类型',
            //     name: 'type',
            //     type: 'select',
            //     optionList:[
            //         {
            //             optionKey:'',
            //             optionShow:''
            //         },{
            //             optionKey:'0',
            //             optionShow:'正品'
            //         },{
            //             optionKey:'1',
            //             optionShow:'样品'
            //         }
            //     ]
            // },{
                showName: '下线时间',
                name:'gmtCreate',
                type: 'date',
                maxName:'gmtCreateMax',
                minName:'gmtCreateMin',
                showTime: '1'
            },{
                showName: '打印状态',
                name:'status',
                type: 'select',
                optionList:[//下拉框的信息
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'0',
                        optionShow:'未打印'
                    },{
                        optionKey:'1',
                        optionShow:'已打印'
                    }
                ]
            },{
                showName: '入库状态',
                name:'userDefined1',
                type: 'select',
                optionList:[//下拉框的信息
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'0',
                        optionShow:'未入库'
                    },{
                        optionKey:'1',
                        optionShow:'已入库'
                    }
                ]
            },
            {
                showName: '生产机号',
                name:'machineNumber',
                type: 'select',
                optionList: []
                // url:'/base/dic/get/machine_number'
            }
        ];

    }
    // 给区域分配角色
    assignFactoryUserHandle = (rowObj) => {
        let workareaId = rowObj.workareaId;
        this.refs.assignFactoryUser.initModal(workareaId);
    }

    rowHandles = (strHandles, rowObj) => {
        console.log("strHandles===ListResource=======", strHandles);
    }

    //刷新列表
    refreshHandle = () => {
        this.refs.listProOutInSn.refreshHandle();
    }

    componentWillMount() {
        const dicType = 'machine_number';
        const options= {
            url: '/base/dic/get/' + dicType,
            type: 'get',
            condition:{}
        };
        //先写死，后面再改
        fetchData(this, options, this.dicInitCallBackHandle);
    }

    //下拉框 初始化
    dicInitCallBackHandle = (resData)=>{
        //alert('resData' + JSON.stringify(resData, null, 4));
        let optionList = [];
        let tmp = {};
        tmp.optionKey = '';
        tmp.optionShow = '';
        optionList.push(tmp);
        resData.data.map( (e,index) => {
            let tmp = {};
            tmp.optionKey = Number(e.dicCode);
            tmp.optionShow = e.dicName;
            optionList.push(tmp);
        });

        //alert('optionList' + JSON.stringify(optionList, null, 4));
        this.tableColumn.data[6].showOption = optionList;
        this.searchComponentData[5].optionList = optionList;
    }

    handleCancel = () => {
    this.setState({ visible: false });
        this.form.resetFields();

    }
    handleCreate = () => {
    const form = this.form;
    form.validateFields((err, values) => {
        if (err) {
        return;
        }

        console.log('Received values of form: ', values);
        form.resetFields();
        this.setState({ visible: false });
    });
    }
    saveFormRef = (form) => {
    this.form = form;
    }


    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return (
            <div>
                <ListBox
                    ref='listProOutInSn'
                    title="退货入库明细"
                    isHideLeft={isHideLeft}
                    tableColumnData={this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url='/product/probarcode/list?userDefined8=TH'
                    rowHandles={this.rowHandles}
                    rowOperation={this.rowOperation}
                    headerOperation={this.headerOperation}
                    isRowSingle = "true"
                />
            
            </div>
        )
    }
}
